<%@ page contentType="text/html;charset=UTF-8"%>
<%@include file="../../common/sessionValidate.jsp" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML>
<html lang="UTF-8">
<head>
    <title>T_order_goods信息维护</title>
    <%@ include file="../../common/meta.jsp"%>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta http-equiv="X-UA-Compatible" content="IE=9">
    <META HTTP-EQUIV="Cache-Control" CONTENT="no-cache, must-revalidate">
    <link rel="stylesheet" href="<%=basePath%>css/my-bootstrap.css" media="screen"  id="tuserskin">
    <link rel="stylesheet" href="<%=basePath%>js/toastr/toastr.css">
    <link rel="stylesheet" href="<%=basePath%>css/bootstrapValidator.min.css">
    <link rel="stylesheet" href="<%=basePath%>css/font-awesome.min.css">
    <script type="text/javascript" src="<%= basePath %>js/jquery.cookie.js"></script>
</head>
<style>
    hr {
        margin-top:1px;
        border-bottom: 1px solid #1BBC9B;
    }
</style>
<body>
<form class="form-horizontal form-bordered form-row-strippe" name="ffAdd" id="ffAdd" mentod="post" role="form" data-toggle="validator" enctype="multipart/form-data">
    <div class="" style="margin-right:2px;padding-right:1px;">

        <!-------------------------- 面板  start--------------------------------->
        <div class="panel panel-primary" >
            <div class="panel-heading clearfix"  id="addHeaderDiv">
            </div>
            <div class="panel-body">
                <div class="row" >
                    <h5>&nbsp;&nbsp;基本信息</h5>
                    <hr>
                    <div class="col-xs-6"><!--start 换列-->
                        <div class="col-xs-12">
                            <div class="form-group">
                                <label class="control-label col-xs-3"><font color="red">*</font> 仓库</label>
                                <div class="col-xs-9">
                                    <select id="buyer_company_name" name="buyer_company_name" class="form-control" >
                                        <option value="">------</option>
                                    </select>
                                    <input id="order_goods_id" name="order_goods_id" type="hidden" />
                                    <input id="kucuntype" name="kucuntype" type="hidden" value="wuye"/>
                                </div>
                            </div>
                        </div>
                        <div class="col-xs-12">
                            <div class="form-group">
                                <label class="control-label col-xs-3"><font color="red">*</font>类别</label>
                                <div class="col-xs-9">
                                    <select id="saller_tel" name="saller_tel" class="form-control" >
                                        <option value="">------</option>
                                    </select>
                                </div>
                            </div>
                        </div>
                        <div class="col-xs-12">
                            <div class="form-group">
                                <label class="control-label col-xs-3"><font color="red">*</font>物料编号</label>
                                <div class="col-xs-9">
                                    <input id="buyer_tel" name="buyer_tel" type="text" class="form-control" placeholder="" />
                                </div>
                            </div>
                        </div>
                        <div class="col-xs-12">
                            <div class="form-group">
                                <label class="control-label col-xs-3">规格型号</label>
                                <div class="col-xs-9">
                                    <input id="saller_company_address" name="saller_company_address" type="text" class="form-control" placeholder="" />
                                </div>
                            </div>
                        </div>
                        <div class="col-xs-12">
                            <div class="form-group">
                                <label class="control-label col-xs-3"><font color="red">*</font>初始库存数量</label>
                                <div class="col-xs-9">
                                    <input id="old_price" name="old_price" type="text" class="form-control" placeholder="" />
                                </div>
                            </div>
                        </div>
                        <div class="col-xs-12">
                            <div class="form-group">
                                <label class="control-label col-xs-3"><font color="red">*</font>当前库存数量</label>
                                <div class="col-xs-9">
                                    <input id="good_num" name="good_num" type="text" class="form-control" placeholder="" />
                                </div>
                            </div>
                        </div>
                        <div class="col-xs-12">
                            <div class="form-group">
                                <label class="control-label col-xs-3"><font color="red">*</font>单位 </label>
                                <div class="col-xs-9">
                                    <input id="ext2" name="ext2" type="text" class="form-control" placeholder="" />
                                </div>
                            </div>
                        </div>
                        <div class="col-xs-12">
                            <div class="form-group">
                                <label class="control-label col-xs-3"> <font color="red">*</font>状态</label>
                                <div class="col-xs-9">
                                    <select id="status" name="status" class="form-control" >
                                        <option value="1">已生效</option>
                                        <option value="0">未生效</option>
                                        <option value="2">其它</option>
                                    </select>
                                </div>
                            </div>
                        </div>
                        <!--如果输入元素是偶数个元素，在n=size/2?int时输出2列格式；如果元素是奇数个，需要在n=size/2?int时输出2列格式；需要换列，每行最多显示2列-->
                    </div><!--end 换列--><!--start 换列-->
                    <div class="col-xs-6">
                        <div class="col-xs-12">
                            <div class="form-group">
                                <label class="control-label col-xs-3">创建者</label>
                                <div class="col-xs-9">
                                    <input id="creater" name="creater" type="text" value="<%=request.getSession().getAttribute("username") %>" class="form-control" placeholder="creater"  readonly="true"/>
                                </div>
                            </div>
                        </div>
                        <div class="col-xs-12">
                            <div class="form-group">
                                <label class="control-label col-xs-3"> 创建时间</label>
                                <div class="col-xs-9">
                                    <input id="creattime" name="creattime" type="text" class="form-control" placeholder="creattime"  readonly="true"/>
                                </div>
                            </div>
                        </div>
                        <div class="col-xs-12">
                            <div class="form-group">
                                <label class="control-label col-xs-3"> 更新者</label>
                                <div class="col-xs-9">
                                    <input id="updater" name="updater" type="text" class="form-control" placeholder="updater" readonly="true" />
                                </div>
                            </div>
                        </div>
                        <div class="col-xs-12">
                            <div class="form-group">
                                <label class="control-label col-xs-3"> 更新时间</label>
                                <div class="col-xs-9">
                                    <input id="updatetime" name="updatetime" type="text" class="form-control" placeholder="updatetime"  readonly="true"/>
                                </div>
                            </div>
                        </div>
                        <div class="col-xs-12">
                            <div class="form-group">
                                <label class="control-label col-xs-3"> 供应商 </label>
                                <div class="col-xs-9">
                                    <input id="saller_company_name" name="saller_company_name" type="text" class="form-control" placeholder="" />
                                </div>
                            </div>
                        </div>
                        <div class="col-xs-12">
                            <div class="form-group">
                                <label class="control-label col-xs-3">批次号</label>
                                <div class="col-xs-9">
                                    <input id="ext1" name="ext1" type="text" class="form-control" placeholder="" />
                                </div>
                            </div>
                        </div>
                        <div class="col-xs-12">
                            <div class="form-group">
                                <label class="control-label col-xs-3">生产日期</label>
                                <div class="col-xs-9">
                                    <input id="ext3" name="ext3" type="text" class="form-control" placeholder="" />
                                </div>
                            </div>
                        </div>
                    </div><!--end 换列-->
                </div><!--end row-->
            </div><!--end body-->

            <div class="modal-footer bg-info " id='buttonDiv'>
            </div>
        </div>
        <!--------------------------面板 end------------------------------------>

    </div>
</form>
</body>
</html>

<script src="<%=basePath%>js/bootstrap.min.js"></script>
<!--<script src="<%=basePath%>js/jquery-1.10.2/jquery.min.js"></script>
<script type="text/javascript" src="js/bootstrapValidator.js"></script>-->
<script src="<%=basePath%>js/bootstrap-paginator.min.js"></script>
<script src="<%=basePath%>/js/respond.js"></script>
<script src="<%=basePath%>/js/html5.js"></script>
<script src="<%=basePath%>js/toastr/toastr.js"></script>
<script src="<%=basePath%>js/bootbox.js"></script>
<script src="<%=basePath%>js/jquery.validate.js"></script>
<!-- <script src="<%=basePath%>js/additional-methods.min.js"></script> -->
<script src="<%=basePath%>js/my-jquery-curd.js"></script>
<script src="<%= basePath %>js/tableSortTool.js" ></script>
<script src="<%= basePath %>js/calendar.js" ></script>
<script type="text/javascript">
    //新增保存数据
    function add() {
        $("#addSaveButton").attr("disabled", true);
        var url = "<%=basePath%>t_order_goods/saveT_order_goods?time="+Math.random();
        var postData = $("#ffAdd").serializeArray();
        //alert(postData);
        $.post(url, postData, function (data) {
            //var data = $.parseJSON(data);
            if (data.result=="success") {
                //保存成功  1.关闭弹出层，
                showSuccessTips("恭喜保存成功!", "提示");
                //history.goBack();
            }
            else {
                $("#addSaveButton").removeAttr("disabled");
                showErrorTips("保存数据失败!", "错误信息：");
                return false;
            }
        }).error(function () {
            $("#addSaveButton").removeAttr("disabled");
            showErrorTips("保存数据失败!", "错误信息：");
        });
    }

    //更新修改数据到后台
    function edit(){
        $("#editSaveButton").attr("disabled", true);
        var url = "<%=basePath%>t_order_goods/updateT_order_goods?time="+Math.random();
        myEdit2(url);
    }

    //初始化数据档案类型下拉框；
    function initDataGroup1(){
        var purl = "<%=basePath%>t_data_dic/getAllT_data_dic?data_group=cangku&flag=1&startIndex=0&pageSize=1000&time="+ Math.random();
        //alert(purl);
        $.ajaxSettings.async = false; //设置为同步，否则会有部分数据没出来
        $.getJSON(purl, function(data) {
            var optionHtml = "";
            $.each(data.items, function(i, item) {
                optionHtml+= "<option value='"+item.data_name+"'>"+item.data_name+"</option>";
            });//end each
            $("#buyer_company_name").append(optionHtml);
            initDataGroup2();
        }); //end getJson
    }

    //初始化数据档案类型下拉框；
    function initDataGroup2(){
        var purl = "<%=basePath%>t_data_dic/getAllT_data_dic?data_group=wuliao&flag=1&startIndex=0&pageSize=1000&time="+ Math.random();
        //alert(purl);
        $.ajaxSettings.async = false; //设置为同步，否则会有部分数据没出来
        $.getJSON(purl, function(data) {
            var optionHtml = "";
            $.each(data.items, function(i, item) {
                optionHtml+= "<option value='"+item.data_name+"'>"+item.data_name+"</option>";
            });//end each
            $("#saller_tel").append(optionHtml);
        }); //end getJson
    }

    //初始化页面及校验
    $().ready(function(){
        //1、初始化数据显示
        var name = "物料库存";
        var optype ='<%=request.getParameter("oplx")%>';
        var id='<%=request.getParameter("id")%>';
        //alert("optype="+optype+";id="+id);
        if(optype=='add'){
            $("#ffAdd")[0].reset();/*重置表单*/
            var basePath="<i class='icon-plus'></i>&nbsp;";
            setHeader2("新增"+name, basePath);//设置addHeaderDiv标题文字及按钮
            setButtonDivAdd2();//设置adddiv的 操作按钮
            initTime("creattime", "1");
            initDataGroup1();

        }else if(optype=='edit'){
            var basePath="<i class='icon-pencil'></i>&nbsp;";
            setHeader2("修改"+name, basePath);//设置addHeaderDiv标题文字及按钮
            setButtonDivEdit2();//设置adddiv的 操作按钮
            initDataGroup1();
            var url = "<%=basePath%>t_order_goods/getT_order_goods?id="+id+"&time="+Math.random();
            $.ajaxSettings.async = false; //设置为同步，否则会有部分数据没出来
            $.getJSON(url, function (data) {//获取数据，并且自动填充form，自动代码待修改； @todo;
                setValue(data);
                //alert($("#effect_date").val()+""+jsonDateFormat($("#effect_date").val()));
                //$("#effect_date").val(jsonDateFormat($("#effect_date").val())); //重新设置日期类型的值
            });
        }else if(optype=='view'){
            var basePath="<i class='icon-eye-open'></i>&nbsp;";//设置addHeaderDiv标题文字及按钮
            setHeader2("查看"+name, basePath);
            setButtonDivView2();//设置adddiv的 操作按钮
            initDataGroup1();
            var url = "<%=basePath%>t_order_goods/getT_order_goods?id="+id+"&time="+Math.random();
            //alert(url);
            $.ajaxSettings.async = false; //设置为同步，否则会有部分数据没出来
            $.getJSON(url, function (data) {//获取数据，并且自动填充form，自动代码待修改； @todo;
                //alert(data.saller_tel);
                setValue(data);
            });
            formReadOnly('ffAdd');//设置表单不可修改
        }

        //2、校验脚本初始化，start check
        $("#ffAdd").validate({
            submitHandler:function(form){
                //alert($("#opType").val());
                if($("#opType").val()=="add"){
                    add();
                }else if($("#opType").val()=="edit"){
                    edit();
                }
            },
            rules: {
                order_goods_id: {
                    //required: true,
                    digits: true,
                    //minlength: 1,
                    maxlength: 11
                },
                order_id: {
                    //required: true,
                    digits: true,
                    //minlength: 1,
                    maxlength: 11
                },
                goods_id: {
                    //required: true,
                    digits: true,
                    //minlength: 1,
                    maxlength: 11
                },
                saller: {
                    //required: true,
                    maxlength: 45
                },
                buyer_company_name: {
                    required: true,
                    maxlength: 128
                },
                buyer_company_address: {
                    required: true,
                    maxlength: 45
                },
                saller_company_address: {
                    //required: true,
                    maxlength: 45
                },
                buyer_tel: {
                    required: true,
                    maxlength: 45
                },
                saller_tel: {
                    required: true,
                    maxlength: 45
                },

                buyer: {
                    //required: true,
                    maxlength: 45
                },
                creater: {
                    //required: true,
                    maxlength: 45
                },
                creattime: {
                    //required: true,
                    maxlength: 45
                },
                updater: {
                    //required: true,
                    maxlength: 45
                },
                updatetime: {
                    //required: true,
                    maxlength: 45
                },
                status: {
                    //required: true,
                    maxlength: 45
                },
                good_num: {
                    required: true,
                    number: true,
                    maxlength: 12
                },
                ext1: {
                    //required: true,
                    maxlength: 45
                },
                ext2: {
                    required: true,
                    maxlength: 45
                },
                ext3: {
                    //required: true,
                    maxlength: 45
                }
            }, //end rules;
            messages: {
                order_goods_id: {
                    //required: " order_goods_id不能为空！",
                    digits: "<font color='red'>请输入数字，不能输入非数字字符！</font>",
                    //minlength: "<font color='red'>最少输入1位！</font>",
                    maxlength: "<font color='red'> order_goods_id最大支持11位，输入的数据已经超过最大长度！</font>"
                },
                order_id: {
                    //required: "订单id不能为空！",
                    digits: "<font color='red'>请输入数字，不能输入非数字字符！</font>",
                    //minlength: "<font color='red'>最少输入1位！</font>",
                    maxlength: "<font color='red'>订单id最大支持11位，输入的数据已经超过最大长度！</font>"
                },
                good_num: {
                    required: "<font color='red'>数量 不能为空！</font>",
                    number: "<font color='red'>请输入 数量，不能输入非数字字符！</font>",
                    //minlength: "<font color='red'>最少输入1位！</font>",
                    maxlength: "<font color='red'> 数量 最大支持12位，输入的数据已经超过最大长度！</font>"
                },

                goods_id: {
                    //required: "商品id不能为空！",
                    digits: "<font color='red'>请输入数字，不能输入非数字字符！</font>",
                    //minlength: "<font color='red'>最少输入1位！</font>",
                    maxlength: "<font color='red'>商品id最大支持11位，输入的数据已经超过最大长度！</font>"
                },
                saller: {
                    maxlength: "<font color='red'>卖家最大支持45位,输入的数据已经超过最大长度！</font>"
                },
                buyer: {
                    maxlength: "<font color='red'>买家最大支持45位,输入的数据已经超过最大长度！</font>"
                },

                buyer_company_name: {
                    required: "<font color='red'>仓库不能为空！</font>",
                    //minlength: "<font color='red'>最少输入1位！</font>",
                    maxlength: "<font color='red'>仓库id最大支持128位，输入的数据已经超过最大长度！</font>"
                },
                saller_company_name: {
                    required: "<font color='red'>商品id不能为空！</font>",
                    //minlength: "<font color='red'>最少输入1位！</font>",
                    maxlength: "<font color='red'>商品id最大支持11位，输入的数据已经超过最大长度！</font>"
                },
                buyer_company_address: {
                    required: "<font color='red'>商品id不能为空！</font>",
                    //minlength: "<font color='red'>最少输入1位！</font>",
                    maxlength: "<font color='red'>商品id最大支持11位，输入的数据已经超过最大长度！</font>"
                },
                saller_company_address: {
                    //required: "<font color='red'>规格型号 不能为空！</font>",
                    //minlength: "<font color='red'>最少输入1位！</font>",
                    maxlength: "<font color='red'> 规格型号 最大支持128位，输入的数据已经超过最大长度！</font>"
                },
                buyer_tel: {
                    required: " <font color='red'>物料编号 不能为空！</font>",
                    //minlength: "<font color='red'>最少输入1位！</font>",
                    maxlength: "<font color='red'>物料编号 最大支持128位，输入的数据已经超过最大长度！</font>"
                },
                saller_tel: {
                    required: "<font color='red'>类别 不能为空！</font>",
                    //minlength: "<font color='red'>最少输入1位！</font>",
                    maxlength: "<font color='red'> 类别 最大支持128位，输入的数据已经超过最大长度！</font>"
                },

                creater: {
                    maxlength: "<font color='red'> creater最大支持45位,输入的数据已经超过最大长度！</font>"
                },
                creattime: {
                    maxlength: "<font color='red'> creattime最大支持45位,输入的数据已经超过最大长度！</font>"
                },
                updater: {
                    maxlength: "<font color='red'> updater最大支持45位,输入的数据已经超过最大长度！</font>"
                },
                updatetime: {
                    maxlength: "<font color='red'> updatetime最大支持45位,输入的数据已经超过最大长度！</font>"
                },
                status: {
                    maxlength: "<font color='red'> status 最大支持45位,输入的数据已经超过最大长度！</font>"
                },
                ext1: {
                    maxlength: "<font color='red'> ext1 最大支持45位,输入的数据已经超过最大长度！</font>"
                },
                ext2: {
                    required: "<font color='red'>单位 不能为空！</font>",
                    maxlength: "<font color='red'> 单位 最大支持45位,输入的数据已经超过最大长度！</font>"
                },
                ext3: {
                    maxlength: "<font color='red'> ext3 最大支持45位,输入的数据已经超过最大长度！</font>"
                }
            } //end message;
        }); //end validate;
    }) //end funciton read;
</script>
